 #include <stdio.h>
 #include <unistd.h>
 #include "ohos_init.h"
 #include "cmsis_os2.h"
 #include "iot_gpio.h"
 #include "hi_gpio.h"
 #include "hi_io.h"
 
 #define KEY_GPIO  HI_GPIO_IDX_14 // ax100  

 #define LED_BLUE   HI_GPIO_IDX_8   // Blue 
 #define LED_RED    HI_GPIO_IDX_2   // Red
 #define LED_GREEN  HI_GPIO_IDX_7   // Green
 
 int g_ledValue = 0;
 int g_keyJitterFlag = 0;

 void KeyISR( char *arg){
    if (g_keyJitterFlag == 1){// 
     return;
    }
   
    printf("Key Down\r\n");
   
    if(g_ledValue == 0 ){
     g_ledValue = 1; 
    printf("Len On\r\n");
    }
    else if(g_ledValue ==1 ){
     g_ledValue = 2; 
    printf("Len Spark\r\n");
    }
    else {
     g_ledValue = 0; 
    printf("Len off\r\n");
    }
   
    g_keyJitterFlag = 1;
   }
static void GpioKeyMain( void ) {
    hi_io_set_func(LED_BLUE, HI_IO_FUNC_GPIO_8_GPIO);
    IoTGpioInit( LED_BLUE );
    IoTGpioSetDir(LED_BLUE, IOT_GPIO_DIR_OUT );
    hi_io_set_func(LED_GREEN, HI_IO_FUNC_GPIO_7_GPIO);
    IoTGpioInit( LED_GREEN );
    IoTGpioSetDir(LED_GREEN, IOT_GPIO_DIR_OUT );
    hi_io_set_func(LED_RED, HI_IO_FUNC_GPIO_2_GPIO);
    IoTGpioInit( LED_RED );
    IoTGpioSetDir(LED_RED, IOT_GPIO_DIR_OUT );

    hi_io_set_func(KEY_GPIO, HI_IO_FUNC_GPIO_14_GPIO);
    IoTGpioInit( KEY_GPIO );
    IoTGpioSetDir( KEY_GPIO, IOT_GPIO_DIR_IN );
    IoTGpioRegisterIsrFunc( KEY_GPIO, IOT_INT_TYPE_EDGE, IOT_GPIO_EDGE_FALL_LEVEL_LOW, KeyISR, NULL );
    IoTGpioSetIsrMask( KEY_GPIO, 0 );

    printf("IoT-LedKey Init OK\r\n");
    while (1) {
        g_keyJitterFlag = 0;
        if(g_ledValue == 0) {IoTGpioSetOutputVal( LED_BLUE, IOT_GPIO_VALUE1 );
            IoTGpioSetOutputVal( LED_GREEN, IOT_GPIO_VALUE0 );
            IoTGpioSetOutputVal( LED_RED, IOT_GPIO_VALUE0 );
        }
        if(g_ledValue == 1) {IoTGpioSetOutputVal( LED_GREEN, IOT_GPIO_VALUE1 );
            IoTGpioSetOutputVal( LED_BLUE, IOT_GPIO_VALUE0 );
            IoTGpioSetOutputVal( LED_RED, IOT_GPIO_VALUE0 );
        }
        if(g_ledValue == 2) {IoTGpioSetOutputVal( LED_RED, IOT_GPIO_VALUE1 );
            IoTGpioSetOutputVal( LED_BLUE, IOT_GPIO_VALUE0 );
            IoTGpioSetOutputVal( LED_GREEN, IOT_GPIO_VALUE0 );
        }
        osDelay( 50 );
    }

    return ;
}

SYS_RUN( GpioKeyMain );   
 